package com.itheima.apitest.objectstest;

import java.util.Objects;

public class ObjectsTest {
    public static void main(String[] args) {
        Student student = new Student("张三", 23);
        Student student2 = new Student("张五", 25);

        // Objects.toString() 返回参数中对象的字符串表示形式
        String result = Objects.toString(student);
        System.out.println(result);
        System.out.println(student+".....");

        // Objects.toString() 返回对象的字符串表示形式
        String result2 = Objects.toString(student2, "嗷呜嗷呜");
        System.out.println(result2);
        Student student3 = null;
        String result3 = Objects.toString(student3, "嗷呜嗷呜");
        System.out.println(result3);

        // Objects.isNull() 判断对象是否为空
        boolean aNull = Objects.isNull(student3);
        System.out.println(aNull);

        // Objects.nonNull() 判断对象是否不为空
        boolean b = Objects.nonNull(student3);
        System.out.println(b);

    }
}

class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
